package jwt

import (
	jwt "gitee.com/sansaniot/ssiot-core/httpmvc/jwtauth"
	"github.com/gin-gonic/gin"

	"ssalarm/common/constant"
)

// 认证, 解析jwt
func IdentityHandler(c *gin.Context) interface{} {
	claims := jwt.ExtractClaims(c)
	return claims[constant.JwtKeyUserName]
}

// 后置操作
func Authorizator(data interface{}, c *gin.Context) bool {
	if data != nil {
		c.Set(constant.JwtKeyUserName, data.(string))
		return true
	}
	return false
}
